import React from "react";
import {ModalForm, ProFormText} from "@ant-design/pro-form/es";
import {Space} from "antd";
import {ProFormDigit} from "@ant-design/pro-form";

const StationInfoForm: React.FC = (props: any) => {
  return (
    <ModalForm<Domain.Station>
      title={props.title}
      trigger={props.trigger}
      autoFocusFirstInput
      modalProps={{
        onCancel: () => console.log('run'),
      }}
      onFinish={async (values) => {
        if (props.handleAdd)
          return await props.handleAdd(values);
        if (props.handleUpdate){
          return await props.handleUpdate(values);
        }
      }}
      layout="horizontal"
      labelCol={{span: 7}}
      wrapperCol={{span: 14}}
      initialValues={props.station}
    >

      <Space direction={"vertical"} size={16}>
        <ProFormText
          width="md"
          name="id"
          label="ID"
          required
          hidden={!props.station}
          disabled
        />

        <ProFormText
          width="md"
          name="city"
          label="所在城市"
          placeholder="请输入城市名称"
          required
        />


        <ProFormText
          width="md"
          name="name"
          label="车站名称"
          placeholder="请输入车站名称"
          required
        />


        <ProFormDigit
          width="md"
          name="xpos"
          label="经度"
          placeholder="请输入经度"
          required
          fieldProps={{
            precision: 2
          }}
        />


        <ProFormDigit
          width="md"
          name="ypos"
          label="纬度"
          placeholder="请输入纬度"
          required
          fieldProps={{
            precision: 2
          }}
        />


      </Space>
    </ModalForm>
  );
}

export default StationInfoForm;
